cmake_minimum_required (VERSION 2.6)
project (Mars)

# should we use our own functions?
option (USE_MYMATH
  "Use Mars provided math implementation" ON)

# add the MathFunctions library?
if (USE_MYMATH)
  include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
  add_subdirectory (MathFunctions)
  set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
endif (USE_MYMATH)

# The version number
set (Mars_VERSION_MAJOR 1)
set (Mars_VERSION_MINOR 0)

set (CMAKE_INSTALL_PREFIX "/home/dragon/tmp/iii")

# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
  "${PROJECT_SOURCE_DIR}/MarsConfig.h.in"
  "${PROJECT_BINARY_DIR}/MarsConfig.h"
  )

# add the binary tree to the search path for include files
# so that we will find MarsConfig.h
include_directories ("${PROJECT_BINARY_DIR}")

# add the executable
add_executable (Jupiter main.cpp)

target_link_libraries (Jupiter ${EXTRA_LIBS})

# add the install targets
install (TARGETS Jupiter DESTINATION bin)
install (FILES "${PROJECT_BINARY_DIR}/MarsConfig.h"
  DESTINATION include)

include (CTest)

# define a macro to simplify adding tests, then use it
macro (do_test arg result)
  add_test (MarsComp${arg} Jupiter ${arg})
  set_tests_properties (MarsComp${arg}
    PROPERTIES PASS_REGULAR_EXPRESSION ${result})
endmacro (do_test)

# do a bunch of result based test
do_test (25 "25 is 5")
do_test (-25 "-25 is 0")
do_test (0.0001 "0.0001 is 0.01")

# # does the application run
# add_test (MarsRuns Jupiter 25)
# # does it sqrt of 25
# add_test (MarsComp25 Jupiter 25)
# set_tests_properties (MarsComp25 PROPERTIES PASS_REGULAR_EXPRESSION "25 is 5")
# # does it handle negative numbers
# add_test (MarsNegative Jupiter -25)
# set_tests_properties (MarsNegative PROPERTIES PASS_REGULAR_EXPRESSION "-25 is 0")
# # does it handle small numbers
# add_test (MarsSmall Jupiter 0.0001)
# set_tests_properties (MarsSmall PROPERTIES PASS_REGULAR_EXPRESSION "0.0001 is 0.01")
# does the usage message work?
add_test (MarsUsage Jupiter)
set_tests_properties (MarsUsage PROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*numbers")
